package com.xhj.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xhj.entity.Course;
import com.xhj.entity.Teacher;
import com.xhj.service.CourseService;
import com.xhj.service.TeacherService;
import com.xhj.util.ResultEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/EduAdmin/index")
@CrossOrigin
public class IndexController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    @ApiOperation(value = "获取首页热门课程和老师")
    @RequestMapping("list")
    public ResultEntity getCourseAndTeacherList(){
        QueryWrapper<Course> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper
                .orderByDesc("id")
                .last("limit 8");
        List<Course> courseList = courseService.list(courseQueryWrapper);

        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id").last("limit 4");
        List<Teacher> teacherList = teacherService.list(teacherQueryWrapper);

        return ResultEntity.successWithData().data("courseList",courseList).data("teacherList",teacherList);
    }
}
